{% extends "staff/base.html" %}
{% import 'staff/_formhelpers.html' as forms %}

{% block title %} bCourses - {{ current_course.display_name_with_semester }}{% endblock %}

{% block main %}
<section class="content-header">
    <h1>
        {{ current_course.display_name_with_semester }} bCourses
        <small>{{ current_course.offering }}</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{{ url_for(".course", cid=current_course.id) }}">
            <i class="fa fa-university"></i> {{ current_course.offering }}
        </a></li>
        <li class="active"><a href="#">
            <i class="fa fa-address-book"></i>bCourses
        </a></li>
    </ol>
</section>

<section class="content">
    {% include 'alerts.html' %}
    <div class="row">
        <div class="col-md-12">
          <div class="box">
              <div class="box-header">
                  <h3 class="box-title">Enrollment</h3>
              </div>

              <!-- /.box-header -->
              <div class="box-body">
                  <div class="btn-toolbar">
                      <div class="btn-group">
                          {% call forms.render_form_bare(CSRFForm(), action_url=url_for('.enroll_canvas_course', cid=current_course.id)) %}
                          <button type="submit" class="btn btn-primary">
                              <i class="fa fa-download"></i> Enroll Students from bCourses
                          </button>
                          {% endcall %}
                      </div>
                  </div>
              </div>
              <!-- /.box-body -->

          </div>
          <div class="box">
              <div class="box-header">
                  <h3 class="box-title"><span>Assignments</span></h3>
                  <div class="box-tools pull-right">
                    <div class="btn-toolbar">
                      <div class="btn-group">
                        <a class="btn btn-primary" href="{{url_for('.edit_canvas_assignment', cid=current_course.id)}}">
                          <i class="fa fa-plus"></i> Add Assignment
                        </a>
                      </div>
                      <div class="btn-group">
                      {% call forms.render_form_bare(CSRFForm(),
                        action_url=url_for('.upload_canvas_course', cid=current_course.id)) %}
                        <button class='btn btn-primary'><i class='fa fa-upload'></i> Upload All Scores</button>
                      {% endcall %}
                      </div>
                    </div>
                  </div>
              </div>

              <!-- /.box-header -->
              <div class="box-body table-responsive no-padding table-loading">
                  <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>OK Assignment</th>
                          <th>bCourses Assignment</th>
                          <th>Scores</th>
                          <th>Actions</th>
                        </tr>
                      </thead>
                      <tbody>
                      {% for canvas_assignment in canvas_assignments %}
                        <tr>
                          <td>
                            <a href="{{ url_for('.assignment', cid=current_course.id, aid=canvas_assignment.assignment_id) }}">
                              {{ canvas_assignment.assignment.display_name }}
                            </a>
                          </td>
                          <td>
                            <a href="{{ canvas_assignment.url }}">
                              {{ external_names.get(canvas_assignment.external_id, canvas_assignment.external_id) }}
                            </a>
                          </td>
                          <td>{{ canvas_assignment.score_kinds | join(', ') }}</td>
                          <td>
                            <div class="btn-toolbar">
                              <div class="btn-group">
                                {% call forms.render_form_bare(CSRFForm(),
                                    action_url=url_for('.upload_canvas_assignment', cid=current_course.id, canvas_assignment_id=canvas_assignment.id)) %}
                                  <button class='btn btn-primary'><i class='fa fa-upload'></i> Upload Scores</button>
                                {% endcall %}
                              </div>
                              <div class="btn-group">
                                <a class="btn btn-sm btn-default" href="{{ url_for('.edit_canvas_assignment', cid=current_course.id, canvas_assignment_id=canvas_assignment.id) }}">
                                  <i class='fa fa-pencil'></i>
                                </a>
                              </div>
                              <div class="btn-group">
                                {% call forms.render_form_bare(CSRFForm(),
                                    action_url=url_for('.delete_canvas_assignment', cid=current_course.id, canvas_assignment_id=canvas_assignment.id)) %}
                                  <button class='btn btn-sm btn-danger' data-confirm='Are you sure you want to delete {{ canvas_assignment.assignment.display_name }}?'><i class='fa fa-trash-o'></i></button>
                                {% endcall %}
                              </div>
                            </div>
                          </td>
                        </tr>
                      {% endfor %}
                      </tbody>
                  </table>
              </div>
              <!-- /.box-body -->

          </div>

          <div class="box">
              <div class="box-header">
                  <h3 class="box-title"><span>Configuration</span></h3>
              </div>

              <!-- /.box-header -->
              <div class="box-body">
                  <p>
                    URL: <a href="{{ canvas_course.url }}">{{ canvas_course.url }}</a>
                  </p>
                  <div class="btn-toolbar">
                      <div class="btn-group">
                          <a class="btn btn-default" href="{{ url_for('.edit_canvas_course', cid=current_course.id) }}">
                              Edit bCourses Configuration
                          </a>
                      </div>
                      <div class="btn-group">
                          {% call forms.render_form_bare(CSRFForm(), action_url=url_for('.delete_canvas_course', cid=current_course.id)) %}
                          <button type="submit" class="btn btn-danger"
                              data-confirm="Are you sure you want to delete this bCourses configuration?">
                              Delete bCourses Configuration
                          </button>
                          {% endcall %}
                      </div>
                  </div>
              </div>
              <!-- /.box-body -->

          </div>

        </div>
    </div>
</section>
{% endblock %}
